<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>数据表管理页面</title>
<!-- 设置网页图标 -->
<link rel="shortcut icon" href="../../images/favicon.png" type="image/x-icon" />
<!-- 引入CSS -->
<link rel="stylesheet" href="../../layui/css/layui.css">
<link rel="stylesheet" href="../css/mystyle.css">
<!-- 引入JS -->
<script src="../../layui/layui.js"></script>
<script type="text/javascript">
layui.use([ 'layer', 'table', 'form' ], function() {
	var $ = layui.$,layer = layui.layer,table = layui.table,form = layui.form,router = layui.router();
	/* 数据库ID */
	var dbid=router.search.id;
	/* 数据库模式名 */
	var schema=router.search.schema;
	/* 加载模板 */
	$.ajax({
		type : "GET",
		url : "/templateset/templatesets?page=1&rows=500",
		async : true,
		dataType : "json",
		success : function(data) {
			/* 返回成功处理数据 */
			if (data.code == 200) {
				$.each(data.data.rows, function(idx, row) {
					$('select[name="templateSetId"]').append("<option value='" + row.id + "'>" + row.setName + "</option>");
				});
				/* 一定初始化一次不然事件会失效 */
				form.render();
			}
		}
	});
	table.render({
		elem : '#table_tables',
		id:'layer_table_tables',
		toolbar : '#toolbar_seach',
		title : '数据表表格',
		size : 'lg',
		defaultToolbar : [],
		cols: [[
			 {type:'checkbox'},
             {type:'numbers', width:100, title: '编号', sort: true},
             {field:'tableName', width:500, title: '数据表名', sort: true},
             {field:'engine', width:200, title: '表引擎', sort: true},
             {field:'comments',  title: '表备注'},
             {fixed: 'right', title:'操作', align:'center', toolbar: '#colbar_tools', width:120}
	       	]],
		url : '/table/info/tables?schema='+schema,
		headers: {dbid: dbid},
		height : 'full-5',
		page : true,
		limit : 20,
		limits : [10,20,30,40,60,80,100,200,500],
		even : true,
		request : {
			pageName : 'page',
			limitName : 'rows'
		},
		response : {
			statusCode : 200
		},
		parseData : function(res) {
			return {
				"code" : res.code,
				"msg" : res.msg,
				"count" : res.data.total,
				"data" : res.data.rows
			};
		},
		error : function(xhr,status,error){
	        /*错误信息处理*/
	        var data = JSON.parse(xhr.responseText);
	        layer.msg(data.msg);
		}
	});
	/* 查询事件 */
	form.on('submit(btn_seachform_seach)', function(data) {
		table.reload('layer_table_tables',{
			where:{keyword:data.field.keyword}
		},true);
		$('input[name="keyword"]').val(data.field.keyword);
		return false;
	});
	$(document).on('click', '#btn_seachform_back', function(){
		/* 返回 */
		window.history.back(-1);
	});
	/* 行工具栏事件 */
	table.on('tool(table_tables)', function(obj) {
		switch (obj.event) {
		case 'colbar_enter':
			/* 跳转页面 */
			$('#iframe-main', window.parent.document).attr('src','/html/fields#/dbid='+dbid+'/schema='+schema+'/tablename='+obj.data.tableName);
			break;
		}
	});
	/* 生成代码 */
	form.on('submit(btn_seachform_generate)', function(data) {
		$('#form_gen')[0].reset();
		/* 获取选中行 */
		var rows = table.checkStatus('layer_table_tables');
		if(rows.data.length > 0){
			/* 弹出新增 */
			layer.open({
				type : 1,
				id : 'layer_panle_gen',
				title : '<i class="layui-icon">&#xe609;</i>&nbsp;批量生成代码',
				area : [ '880px', '568px' ],
				shade : 0.3,
				closeBtn : 0,
				content : $('#form_gen'),
				success: function(layero, index){
					 $('input[name="dbId"]').val(dbid);
    				 var tables="";
    				 layui.each(rows.data, function(index,item){
    					 tables=item.tableName+"," + tables;
    				 });
    				 $('input[name="tables"]').val(tables.replace(/^(\s|,)+|(\s|,)+$/g, ''));
				  }
			});
		}else{
			layer.msg('你还未选择数据!',{icon: 0});
		}
		return false;
	});
	/* 生成代码 */
	form.on('submit(btn_genform_gen)', function(data) {
		/* 修改路径设置方法 */
		$("#form_gen").attr("action", "/table/config/generates").attr("method", "POST")
		$('#form_gen').hide();
		layer.closeAll('page');
		layer.msg('下载成功,请前往浏览器下载查看文件！',{icon: 1});
		return true;
	});	
	/* 取消事件 */
	$('#btn_genform_cancel').click(function() {
		$('#form_gen').hide();
		$('#form_gen')[0].reset();
		layer.closeAll('page');
	});	
});
</script>
</head>
<script type="text/html" id="toolbar_seach">
  <div class="layui-fluid">
   <form id="form_seach" class="layui-form layui-form-pane" lay-filter="form_seach">
   <div class="layui-row layui-col-space10">
    <div class="layui-col-md8">
      <input class="layui-input" lay-filter="keyword" name="keyword" lay-verType="tips" lay-verify="" placeholder="表名/备注" autocomplete="off">
    </div>
    <div class="layui-col-md4" style="text-align: right;">
      <button type="submit" lay-submit class="layui-btn" lay-filter="btn_seachform_seach"><i class="layui-icon">&#xe615;</i>&nbsp;查询</button>
      <button type="reset" class="layui-btn layui-btn-danger"><i class="layui-icon">&#xe639;</i>&nbsp;清除</button>
      <button type="submit" lay-submit class="layui-btn layui-btn-normal" lay-filter="btn_seachform_generate"><i class="layui-icon">&#xe609;</i>&nbsp;批量生成</button>
      <button type="button" class="layui-btn layui-btn-warm" id="btn_seachform_back"><i class="layui-icon">&#xe603;</i>&nbsp;返回</button>
    </div>
   </div>
   </form>
  </div>
</script>
<script type="text/html" id="colbar_tools">
  <a class="layui-btn" lay-event="colbar_enter">表字段</a>
</script>
<body>
 <form id="form_gen" class="layui-form layui-form-pane" lay-filter="form_gen" style="padding: 20px 10px; display: none;">
  <input type="hidden" name="dbId">
  <input type="hidden" name="tables">
  <div class="layui-fluid">
   <div class="layui-row layui-col-space10">
    <div class="layui-col-md6">
      <label class="layui-form-label">请选择模板</label>
      <div class="layui-input-block">
        <select name="templateSetId" lay-filter="templateset_select">
          <option value="" selected>系统默认模板</option>
        </select>
      </div>
    </div>   
    <div class="layui-col-md6">
      <label class="layui-form-label">作者名</label>
      <div class="layui-input-block">
        <input type="text" name="author" autocomplete="off" lay-verType="tips" lay-verify="required" placeholder="请输入作者名" class="layui-input" value="LiuGangQiang">
      </div>
    </div>
   </div>
   <div class="layui-row layui-col-space10">
    <div class="layui-col-md6">
      <label class="layui-form-label">去掉表前缀</label>
      <div class="layui-input-block">
        <input type="text" name="prefix" autocomplete="off" lay-verType="tips" lay-verify="" placeholder="请输入需要去掉的表前缀" class="layui-input">
      </div>
    </div>
    <div class="layui-col-md6">
      <label class="layui-form-label">包名</label>
      <div class="layui-input-block">
        <input type="text" name="packageName" autocomplete="off" lay-verType="tips" lay-verify="required" placeholder="请输入包名" class="layui-input" value="com">
      </div>
    </div>
   </div>    
   <div class="layui-row layui-col-space10">
    <div class="layui-col-md6">
      <label class="layui-form-label">Entity名</label>
      <div class="layui-input-block">
        <input type="text" name="entityName" autocomplete="off" lay-verType="tips" lay-verify="required" placeholder="请输入Entity名" class="layui-input" value="%sPo">
      </div>
    </div>
    <div class="layui-col-md6">
      <label class="layui-form-label">Mapper名</label>
      <div class="layui-input-block">
        <input type="text" name="mapperName" autocomplete="off" lay-verType="tips" lay-verify="required" placeholder="请输入Mapper名" class="layui-input" value="%sDao">
      </div>
    </div>
   </div>
   <div class="layui-row layui-col-space10">
    <div class="layui-col-md6">
      <label class="layui-form-label">XML名</label>
      <div class="layui-input-block">
        <input type="text" name="xmlName" autocomplete="off" lay-verType="tips" lay-verify="required" placeholder="请输入XML名" class="layui-input" value="%sDao">
      </div>
    </div>
    <div class="layui-col-md6">
      <label class="layui-form-label">IService名</label>
      <div class="layui-input-block">
        <input type="text" name="serviceName" autocomplete="off" lay-verType="tips" lay-verify="required" placeholder="请输入IService名" class="layui-input" value="I%sService">
      </div>
    </div>
   </div>     
   <div class="layui-row layui-col-space10">
    <div class="layui-col-md6">
      <label class="layui-form-label">Service名</label>
      <div class="layui-input-block">
        <input type="text" name="serviceImplName" autocomplete="off" lay-verType="tips" lay-verify="required" placeholder="请输入Service名" class="layui-input" value="%sService">
      </div>
    </div>
    <div class="layui-col-md6">
      <label class="layui-form-label">Controller名</label>
      <div class="layui-input-block">
        <input type="text" name="controllerName" autocomplete="off" lay-verType="tips" lay-verify="required" placeholder="请输入Controller名" class="layui-input" value="%sController">
      </div>
    </div>
   </div>
   <div class="layui-row layui-col-space10">
    <div class="layui-col-md6">
      <label class="layui-form-label">Entity包名</label>
      <div class="layui-input-block">
        <input type="text" name="entityPackage" autocomplete="off" lay-verType="tips" lay-verify="required" placeholder="请输入Entity包名" class="layui-input" value="model.po">
      </div>
    </div>
    <div class="layui-col-md6">
      <label class="layui-form-label">IService包名</label>
      <div class="layui-input-block">
        <input type="text" name="servicePackage" autocomplete="off" lay-verType="tips" lay-verify="required" placeholder="请输入IService包名" class="layui-input" value="service.iface">
      </div>
    </div>
   </div>
   <div class="layui-row layui-col-space10">
    <div class="layui-col-md6">
      <label class="layui-form-label">Service包名</label>
      <div class="layui-input-block">
        <input type="text" name="serviceImplPackage" autocomplete="off" lay-verType="tips" lay-verify="required" placeholder="请输入Service包名" class="layui-input" value="service.impl">
      </div>
    </div>
    <div class="layui-col-md6">
      <label class="layui-form-label">Mapper包名</label>
      <div class="layui-input-block">
        <input type="text" name="mapperPackage" autocomplete="off" lay-verType="tips" lay-verify="required" placeholder="请输入Mapper包名" class="layui-input" value="dao">
      </div>
    </div>
   </div>     
   <div class="layui-row layui-col-space10">
    <div class="layui-col-md6">
      <label class="layui-form-label">Controller包名</label>
      <div class="layui-input-block">
        <input type="text" name="controllerPackage" autocomplete="off" lay-verType="tips" lay-verify="required" placeholder="请输入Controller包名" class="layui-input" value="controller">
      </div>
    </div>
    <div class="layui-col-md6">
      <label class="layui-form-label">DTO包名</label>
      <div class="layui-input-block">
        <input type="text" name="dtoPackage" autocomplete="off" lay-verType="tips" lay-verify="required" placeholder="请输入DTO包名" class="layui-input" value="model.dto">
      </div>
    </div>
   </div>     
   <div class="layui-row layui-col-space10">
    <div class="layui-col-md6">
      <label class="layui-form-label">VO包名</label>
      <div class="layui-input-block">
        <input type="text" name="voPackage" autocomplete="off" lay-verType="tips" lay-verify="required" placeholder="请输入VO包名" class="layui-input" value="model.vo">
      </div>
    </div>
    <div class="layui-col-md6">
      <label class="layui-form-label">Convert包名</label>
      <div class="layui-input-block">
        <input type="text" name="convertPackage" autocomplete="off" lay-verType="tips" lay-verify="required" placeholder="请输入Convert包名" class="layui-input" value="model.convert">
      </div>
    </div>
   </div>     
   <div class="layui-row layui-col-space10">    
    <div class="layui-col-md12" style="text-align: right;">
      <button type="submit" class="layui-btn layui-btn-normal" lay-filter="btn_genform_gen" lay-submit>生成并下载</button>
      <button type="reset" class="layui-btn">重置</button>
      <button type="button" class="layui-btn layui-btn-danger" id="btn_genform_cancel">取消</button>    
    </div>    
   </div>
  </div>
 </form>
 <table class="layui-hide" id="table_tables" lay-filter="table_tables"></table>
</body>
</html>